// auth.middleware.ts
import { Injectable, NestMiddleware } from '@nestjs/common';
import { Request, Response, NextFunction } from 'express';

@Injectable()
export class AuthMiddleware implements NestMiddleware {
  use(req: Request, res: Response, next: NextFunction) {
    const authHeader = req.headers['authorization'];
    
    if (!authHeader) {
      return res.status(401).json({ message: 'Authorization header missing' });
    }
    
    const token = authHeader.replace('Bearer ', '');
    
    // 验证 token
    if (!this.verifyToken(token)) {
      return res.status(401).json({ message: 'Invalid token' });
    }
    
    next();
  }

  private verifyToken(token: string): boolean {
    // 实现你的 token 验证逻辑
    return token === 'valid-token';
  }
}